package cn.edu.nju.software.zp13.core2.nodeGenerator.factory;

import java.lang.reflect.InvocationTargetException;

import org.w3c.dom.Document;

import cn.edu.nju.software.zp13.core2.nodeDescriptor.NodeDescriptor;
import cn.edu.nju.software.zp13.core2.nodeGenerator.NodeGenerator;

public class NodeGeneratorFactory {
	public static NodeGenerator createNodeGenerator(Document dom, NodeDescriptor nd) {
		NodeGenerator ng = null;
		String className = NodeGenerator.class.getPackage().getName() + "." + nd.getType() + "Generator";
		try {
			@SuppressWarnings("unchecked")
			Class<? extends NodeGenerator> clazz = (Class<? extends NodeGenerator>) Class.forName(className);
			try {
				ng = clazz.getConstructor(Document.class).newInstance(dom);
			} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
					| IllegalArgumentException | InvocationTargetException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return ng;
	}
}
